package com.micro.modual.controller;

import com.micro.core.resp.RespJson;
import com.micro.core.resp.RespJsonData;
import com.micro.core.resp.RespJsonPageData;
import com.micro.modual.model.bo.seckill.SeckillBO;
import com.micro.modual.model.bo.seckill.SeckillStatusBO;
import com.micro.modual.model.bo.seckillactivitysence.ActivitySenceBO;
import com.micro.modual.model.bo.seckillactivitysence.SeckillActivitySenceBO;
import com.micro.modual.model.bo.seckilldetail.SeckillDetailBO;
import com.micro.modual.model.bo.seckilldetail.SeckillDetailListBO;
import com.micro.modual.model.bo.seckillscene.SeckillSceneBO;
import com.micro.modual.model.dto.goodssku.GoodsSkuListDTO;
import com.micro.modual.model.dto.seckill.SeckillDetailDTO;
import com.micro.modual.model.dto.seckill.SeckillListDTO;
import com.micro.modual.model.dto.seckillactivitysence.ActivitySenceDTO;
import com.micro.modual.model.dto.seckilldetail.SeckillDetailListDTO;
import com.micro.modual.model.dto.seckillscene.SeckillSceneDetailDTO;
import com.micro.modual.model.dto.seckillscene.SeckillSceneListDTO;
import com.micro.modual.service.SeckillActivitySenceService;
import com.micro.modual.service.SeckillDetailService;
import com.micro.modual.service.SeckillSceneService;
import com.micro.modual.service.SeckillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;

import java.text.ParseException;
import java.util.List;
import java.util.Map;

/**
 * <h1>秒杀表 控制器</h1>
 * @author levelcoder
 * @version V1.0.0
 * @email LevelCoder@126.com
 * @date 2020-08-04 00:27:47
 */
@Api(value = "秒杀管理",tags = "秒杀管理")
@RestController
@RequestMapping(value = "seckill")
public class SeckillController {

    @Autowired
    private SeckillService seckillService;

    @Autowired
    private SeckillSceneService seckillSceneService;

    @Autowired
    private SeckillActivitySenceService seckillActivitySenceService;

    @Autowired
    private SeckillDetailService seckillDetailService;

    /**
     * <h2>查找秒杀表 列表</h2>
     * @param params 列表查询请求对象
     * @return List<SeckillListDTO> {@link SeckillListDTO}s  秒杀表 列表返回对象
     */
    @ApiOperation(value = "查询秒杀表列表" ,notes = "查询秒杀表列表")
    @GetMapping(value = "/findSeckillList")
    public RespJsonPageData<SeckillListDTO> findSeckillList(@RequestParam  Map<String,Object> params){
        return seckillService.findList(params,SeckillListDTO.class);
    }

    /**
     * <h2>根据主键编号查看秒杀表详情</h2>
     * @param id  秒杀表 主键编号
     * @return {@link SeckillDetailDTO}  秒杀表 详情
     */
    @ApiOperation(value = "查询秒杀表详情",notes = "根据主键编号，查询秒杀表详情")
    @GetMapping(value = "/findSeckillDetail/{id}")
    public RespJsonData<SeckillDetailDTO> findSeckillDetail(@PathVariable("id") Long id){
        return seckillService.findDetail(id,SeckillDetailDTO.class);
    }

    /**
     * <h2>新增秒杀表详情</h2>
     * @param seckillBO {@link SeckillBO} 秒杀表 新增/修改 请求对象
     * @return {@link RespJson} 返回结果基础类
     */
    @ApiOperation(value = "新增秒杀表",notes = "新增秒杀表")
    @PostMapping(value = "/addSeckill")
    public RespJson addSeckill(@RequestBody SeckillBO seckillBO){
        return seckillService.addSeckill(seckillBO);
    }

    /**
     * <h2>修改秒杀表详情</h2>
     * @param seckillBO  {@link SeckillBO} 秒杀表 新增/修改 请求对象
     * @return {@link RespJson} 返回结果基础类
     */
    @ApiOperation(value = "修改秒杀表",notes = "修改秒杀表")
    @PostMapping(value = "/editSeckill")
    public RespJson editSeckill(@RequestBody SeckillBO seckillBO){
        return seckillService.editSeckill(seckillBO);
    }

    /**
     * <h2>根据主键编号删除秒杀表信息</h2>
     * @param id  秒杀表 主键编号
     * @return  {@link RespJson} 返回结果基础类
     */
    @ApiOperation(value = "删除秒杀表",notes = "根据地址ID，删除秒杀表")
    @PostMapping(value = "/deleteSeckill/{id}")
    public RespJson deleteSeckill(@PathVariable("id") Long id){
        return seckillService.deleteSeckill(id);
    }

    /**
     * <h2>修改秒杀状态</h2>
     * @param seckillStatusBO
     * @return
     */
    @PostMapping(value = "/modifySeckillOnlineStatus")
    public RespJson modifySeckillOnlineStatus(@RequestBody SeckillStatusBO seckillStatusBO) throws ParseException {
        return seckillService.modifySeckillOnlineStatus(seckillStatusBO);
    }


    /**
     * <h2>查找秒杀场次设置表 列表</h2>
     * @param params 列表查询请求对象
     * @return List<SeckillSceneListDTO> {@link SeckillSceneListDTO}s  秒杀场次设置表 列表返回对象
     */
    @ApiOperation(value = "查询秒杀场次设置表列表" ,notes = "查询秒杀场次设置表列表")
    @GetMapping(value = "/findSeckillSceneList")
    public RespJsonPageData<SeckillSceneListDTO> findSeckillSceneList(@RequestParam  Map<String,Object> params){
        return seckillSceneService.findList(params,SeckillSceneListDTO.class);
    }

    /**
     * <h2>新增秒杀场次设置表详情</h2>
     * @param seckillSceneBO {@link SeckillSceneBO} 秒杀场次设置表 新增/修改 请求对象
     * @return {@link RespJson} 返回结果基础类
     */
    @ApiOperation(value = "新增秒杀场次设置表",notes = "新增秒杀场次设置表")
    @PostMapping(value = "/addSeckillScene")
    public RespJson addSeckillScene(@RequestBody SeckillSceneBO seckillSceneBO){
        return seckillSceneService.addSeckillScene(seckillSceneBO);
    }

    /**
     * <h2>根据主键编号删除秒杀场次设置表信息</h2>
     * @param id  秒杀场次设置表 主键编号
     * @return  {@link RespJson} 返回结果基础类
     */
    @ApiOperation(value = "删除秒杀场次设置表",notes = "根据地址ID，删除秒杀场次设置表")
    @PostMapping(value = "/deleteSeckillScene/{id}")
    public RespJson deleteSeckillScene(@PathVariable("id") Long id){
        return seckillSceneService.deleteSeckillScene(id);
    }

    /**
     * <h2>根据活动编号查询时间区间</h2>
     * @param seckillCode  秒杀活动编号
     * @return
     */
    @ApiOperation(value = "根据活动编号查询时间区间",notes = "根据活动编号查询时间区间")
    @GetMapping(value = "/findActivitySenceList/{seckillCode}")
    public RespJsonData<List<ActivitySenceDTO>> findActivitySenceList(@PathVariable("seckillCode") String seckillCode){
        return seckillActivitySenceService.findActivitySenceList(seckillCode);
    }


    /**
     * <h2>新增秒杀活动场次关联表详情</h2>
     * @param seckillActivitySenceBO {@link SeckillActivitySenceBO} 秒杀活动场次关联表 新增/修改 请求对象
     * @return {@link RespJson} 返回结果基础类
     */
    @ApiOperation(value = "新增秒杀活动场次关联表",notes = "新增秒杀活动场次关联表")
    @PostMapping(value = "/addActivitySence")
    public RespJson addSeckillActivitySence(@RequestBody SeckillActivitySenceBO seckillActivitySenceBO){
        return seckillActivitySenceService.addSeckillActivitySence(seckillActivitySenceBO);
    }

    /**
     * <h2>查询时间区间:排除已经关联的</h2>
     * @param seckillCode  秒杀活动编号
     * @return
     */
    @ApiOperation(value = "查询时间区间",notes = "查询时间区间")
    @GetMapping(value = "/findTimeSectionList/{seckillCode}")
    public RespJsonData<List<SeckillSceneDetailDTO>> findTimeSectionList(@PathVariable("seckillCode") String seckillCode){
        return seckillSceneService.findTimeSectionList(seckillCode);
    }

    /**
     * <h2>移除活动时间关联</h2>
     * @param id
     * @return
     */
    @PostMapping(value = "/removeActivitySence/{id}")
    public RespJson removeActivitySence(@PathVariable("id") Long id){
        return seckillActivitySenceService.removeActivitySence(id);
    }

    /**
     * <h2>查找秒杀商品详情表 列表</h2>
     * @param params 列表查询请求对象
     * @return List<SeckillDetailListDTO> {@link SeckillDetailListDTO}s  秒杀商品详情表 列表返回对象
     */
    @ApiOperation(value = "查询秒杀商品详情表列表" ,notes = "查询秒杀商品详情表列表")
    @GetMapping(value = "/findSeckillDetailList")
    public RespJsonPageData<SeckillDetailListDTO> findSeckillDetailList(@RequestParam  Map<String,Object> params){
        return seckillDetailService.findSeckillDetailList(params);
    }

    /**
     * <h2>查询所有商品信息</h2>
     * @param seckillDetailListBO
     * @return
     */
    @GetMapping(value = "/findGoodsSkuAll")
    public RespJsonData<List<GoodsSkuListDTO>> findGoodsSkuAll(SeckillDetailListBO seckillDetailListBO){
        return seckillDetailService.findGoodsSkuAll(seckillDetailListBO);
    }

    /**
     * <h2>新增秒杀商品详情表详情</h2>
     * @param seckillDetailBO {@link SeckillDetailBO} 秒杀商品详情表 新增/修改 请求对象
     * @return {@link RespJson} 返回结果基础类
     */
    @ApiOperation(value = "新增秒杀商品详情表",notes = "新增秒杀商品详情表")
    @PostMapping(value = "/addSeckillDetail")
    public RespJson addSeckillDetail(@RequestBody SeckillDetailBO seckillDetailBO){
        return seckillDetailService.addSeckillDetail(seckillDetailBO);
    }

    /**
     * <h2>根据主键编号删除秒杀商品详情表信息</h2>
     * @param id  秒杀商品详情表 主键编号
     * @return  {@link RespJson} 返回结果基础类
     */
    @ApiOperation(value = "删除秒杀商品详情表",notes = "根据地址ID，删除秒杀商品详情表")
    @PostMapping(value = "/deleteSeckillDetail/{id}")
    public RespJson deleteSeckillDetail(@PathVariable("id") Long id){
        return seckillDetailService.deleteSeckillDetail(id);
    }

}

